/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// ptextbox.hpp - Text box class definition.
//
// Author: Kenneth G. Maxwell
//
// Copyright (c) 1997-2000 Swell Software 
//              All Rights Reserved.
//
// Unauthorized redistribution of this source code, in whole or part,
// without the express written permission of Swell Software
// is strictly prohibited.
//
// Notes:
//
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef _PEGTEXTBOX_
#define _PEGTEXTBOX_

#ifndef PEG_TB_WHITESPACE
#define PEG_TB_WHITESPACE 2     // white space to leave on borders
#endif

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegTextBox : public PegWindow
{
    public:
        PegTextBox(const PegRect &Rect, PEGUINT StringId = 0,
                   PEGUSHORT Id = 0,
                   PEGULONG Style = FF_RECESSED|EF_WRAP|TJ_LEFT,
                   PEGINT MaxChars = 1000);

        PegTextBox(const PEGCHAR *pText, const PegRect &Rect,
            PEGUSHORT Id = 0,
            PEGULONG Style = TT_COPY|FF_RECESSED|EF_WRAP|TJ_LEFT,
            PEGINT MaxChars = 1000);

        virtual ~PegTextBox();

        virtual void Append(PEGINT StringId);
        virtual void Append(const PEGCHAR *pText);

        void CheckBufLen(PEGINT Len);

        virtual void DataSet(PEGUINT StringId);
        virtual void DataSet(const PEGCHAR *Text);
 
        virtual void Draw(const PegRect &Invalid);
        const PEGCHAR *FindLinePointer(PEGINT Line);
        virtual void GetHScrollInfo(PegScrollInfo *Put);
        PEGINT GetLineIndex(PEGINT Line);
        const PEGCHAR *GetLineStart(PEGINT Line, PEGINT *pPutLen);

        PEGUINT GetMaxChars(void) {return mMaxChars;}
        PEGUINT GetTopLine(void) {return mTopLine;}
        virtual void GetVScrollInfo(PegScrollInfo *Put);
        PEGINT GetWidestLine(void) {return mWidestLine;}

        PEGINT LineCount(void) {return mTotalLines;}
        PEGBOOL LineDown(void);
        PEGBOOL LineUp(void);
        void MarkLine(PEGINT MarkLine) {mMarkLine = MarkLine;}
        virtual PEGINT Message(const PegMessage &Mesg);
        virtual void Resize(const PegRect &NewSize);

        void RewindDataSet(PEGINT StringId);
        void RewindDataSet(const PEGCHAR *pText);

        void SetBorderWhitespace(PEGINT Space);
        virtual void SetFont(PEGUINT FontIndex);
        void SetInterlineSpace(PEGINT Space);
        void SetMaxChars(PEGINT MaxChars) {mMaxChars = MaxChars;}

        virtual void SetScrollMode(PEGUINT Mode)
        {
            PegWindow::SetScrollMode(Mode);
            UpdateLineStarts();
        }

        void SetTopLine(PEGINT Line);
        void SetTopLineToEnd(void);

    protected:

        void ClipToClient(const PegRect &Invalid);
        virtual void DrawAllText(const PegRect &Invalid);
        virtual void DrawTextLine(PEGINT Line, PegPoint PutPoint, 
                                  PEGBOOL Fill = FALSE);
        void EndClipToClient(void);

        void FillLineStarts(PEGINT StartLine, PEGBOOL Full);
        virtual const PEGCHAR *FindNextLine(const PEGCHAR *pText, PEGINT MaxWidth, 
                                    PEGINT Dir = 1);

        void Initialize(PEGUSHORT ID, PEGULONG Style, PEGINT MaxChars);

        void NewDataSet(void);
        void UpdateLineStarts(void);

        PEGINT *mpLineStarts;
        PEGCHAR *mpBuf;

        PEGINT mWidestLine;
        PEGINT mLeftOffset;
        PEGINT mTotalLines;
        PEGINT mVisible;
        PEGINT mLineStartTop;
        PEGINT mLineStartEnd;
        PEGINT mLineHeight;
        PEGINT mInterLineSpace;
        PEGINT mWhiteSpace;
        PEGINT mBufLen;
        PEGINT mMaxChars;
        PEGINT mTopLine;
        PEGINT mMarkLine;
};


#endif

